import { Toast } from "vant"
import {createRouter,createMemoryHistory} from "vue-router"
 const router = createRouter({
  history:createMemoryHistory(),
  routes:[
    {
      path:'/',
      component:()=>import('../Pages/myHome/MyHome.vue')
    },
    {
      path:'/home',
      component:()=>import('../Pages/myHome/MyHome.vue')
    },
    {
      path:'/cart',
      component:()=>import('../Pages/myCart/MyCart.vue'),
      meta:{
        isAuth:true
      }
    },
    {
      path:'/order',
      component:()=>import('../Pages/myOrder/MyOrder.vue'),
      meta:{
        isAuth:true
      }
    },
    {
      path:'/mine',
      component:()=>import('../Pages/mine/Mine.vue'),
      meta:{
        isAuth:true
      }
    },
    {
      path:'/store',
      component:()=>import('../Pages/myStore/MyStore.vue')
    },
    {
      path:'/createorder',
      component:()=>import('../Pages/createOrder/CreateOrder.vue')
      ,
      meta:{
        isAuth:true
      }
    },
    {
      path:'/address',
      component:()=>import('../Pages/address/Address.vue'),
      meta:{
        isAuth:true
      }
    },
    {
      path:'/addressEdit',
      component:()=>import('../Pages/addressEdit/AddressEdit.vue'),
      meta:{
        isAuth:true
      }
    },
    {
      path:'/login',
      component:()=>import('../Pages/login/Login.vue')
    },
    {
      path:'/register',
      component:()=>import('../Pages/register/Register.vue')
    },
    {
      path:'/userinfoedit',
      component:()=>import('../Pages/userinfoedit/UserInfoEdit.vue')
    },
  ]
 })


 router.beforeEach((to,from,next)=>{
  if(to.meta.isAuth){
    if(localStorage.isLogin==='1'){
      next()
    }else{
      Toast('请先登录')
      router.push('./login')
    }
  }else{
    next()
  }
 })

 export default router;